var express = require('express'),
	newupfile = require('../module/mu'),
	db = require('../pubModule/mysql'),
	config = require('../config'),
	bodyParser = require('body-parser'),
	encode = require('../pubModule/crypto'),
	check = require('../module/check'),
	up = express();

/*
*	get上传页面，要通过cookies，与session验证
*/
up.get('/',function(req, res){
	try{
		check.checkCookies(req.cookies.userName,
			encode.encrypto(req.session.userName),
			function(){
				res.render('upVideo',{'action':'/up'});
			}, function(){
				res.render('log',{})
			});
	} catch(e) {
		res.render('log',{})
	}
})

/*
*	post 也要验证
*/
up.post('/',function(req, res){
	try{
		check.checkCookies(req.cookies.userName,
			encode.encrypto(req.session.userName),
			function(){
				newupfile.newFiles(req, config.PATH, function(date){
					res.json(date)
				}, function jindu(status){
					req.session.jin = status
				})
			}, function(){
				res.render('log',{})
			}
		)
	} catch(e) {
		res.render('log',{})
	}
})

/*
*	get文件上传进度
*/
up.get('/ajax',function(req, res){
	res.json({'jin':req.session.jin})
})

/*
*	表单提交
*/
up.get('/ajaxInfo', function(req, res){
	console.log(req.query.vName)
	try{
		check.cookies(req.cookies.userName,
			encrypto(req.session.userName),
			function(){
				//
			},function(){
				res.render('log',{})
			}
		)
	} catch (e) {

	}
	res.send('ssss');
})

module.exports = up;